<template>
	<div class="system-user-dialog-container">
		<el-dialog :title="state.dialog.title" v-model="state.dialog.isShowDialog" width="769px">
			<el-form ref="dealerEditDialogFormRef" :model="ruleForm" size="default" label-width="120px">
				<el-row :gutter="35">
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="代理商名称" prop="orgName">
							<el-input v-model="ruleForm.orgName" :disabled="true" placeholder="请输入名称" clearable></el-input>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="联系电话" prop="orgContact">
							<el-input v-model="ruleForm.orgContact" :disabled="true" placeholder="请输入联系电话" clearable></el-input>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="联系人" prop="userName">
							<el-input :disabled="true" v-model="ruleForm.userName" placeholder="请输入联系人姓名" clearable></el-input>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="手机号" prop="userTel">
							<el-input :disabled="true" v-model="ruleForm.userTel" placeholder="请输入联系人手机号" clearable></el-input>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="负责区域" prop="regions">
							<el-cascader :disabled="true" :options="options" :props="props" clearable v-model="ruleForm.regions" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
						<el-form-item label="地址" prop="orgAddress">
							<el-input :disabled="true" v-model="ruleForm.orgAddress" type="textarea" placeholder="请输入地址" maxlength="150"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
			<template #footer>
				<span class="dialog-footer">
					<el-button type="primary" @click="onSubmit" size="default">{{ state.dialog.submitTxt }}</el-button>
				</span>
			</template>
		</el-dialog>
	</div>
</template>

<script setup lang="ts">
import { reactive, ref } from 'vue';
import { useDealer, DealerVo } from './dealer';
const props = {
	multiple: true,
	checkStrictly: true,
};
// 定义子组件向父组件传值/事件
const options = ref([]);
// 定义变量内容
const dealerEditDialogFormRef = ref();
const ruleForm = reactive<Partial<DealerVo>>({});
const state = reactive({
	dialog: {
		isShowDialog: false,
		type: '',
		title: '',
		submitTxt: '',
	},
});

// 打开弹窗
const openDialog = (row: RowUserType) => {
	setFormData(row);
	// ruleForm.value = row;
	state.dialog.title = '代理商信息';
	state.dialog.submitTxt = '确定';
	state.dialog.isShowDialog = true;
	useDealer()
		.getDivision()
		.then((res: any) => {
			options.value = res;
		});
};
const setFormData = (row: any) => {
	ruleForm.id = row.id;
	ruleForm.orgName = row.orgName;
	ruleForm.orgContact = row.orgContact;
	ruleForm.orgAddress = row.orgAddress;
	ruleForm.userName = row.userName;
	ruleForm.userTel = row.userTel;
	ruleForm.regions = row.regions;
};
// 关闭弹窗
const closeDialog = () => {
	state.dialog.isShowDialog = false;
};

// 提交
const onSubmit = () => {
	closeDialog();
};

// 暴露变量
defineExpose({
	openDialog,
});
</script>
